package com.qf.openapi.web.master.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.openapi.web.master.dao.SystemDao;
import com.qf.openapi.web.master.entity.Systems;
import com.qf.openapi.web.master.service.SystemService;
import com.qf.openapi.web.master.utils.Contants;
import com.qf.openapi.web.master.vo.ResultVo;
import com.qf.openapi.web.master.vo.TableVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemServiceImpl implements SystemService {

    @Autowired
    private SystemDao systemDao;

    @Override
    public TableVo<Systems> table(Integer page, Integer limit, Systems systems) {

        PageHelper.startPage(page,limit);
        List<Systems> data = systemDao.getSysById(systems);
        PageInfo<Systems> pageInfo = new PageInfo<>(data);
        long total = pageInfo.getTotal();
        return TableVo.ok((int)total,data);

    }

    @Override
    public ResultVo add(Systems systems) {

        Integer integer =  systemDao.add(systems);

        if (integer > 0){
            return new ResultVo(Contants.SUCCESS_CODE,"添加成功");
        }else {
            return new ResultVo(Contants.FAIL_CODE,"添加失败");
        }
    }

    @Override
    public ResultVo update(Systems systems) {
        Integer integer =  systemDao.update(systems);

        if (integer > 0){
            return new ResultVo(Contants.SUCCESS_CODE,"修改成功");
        }else {
            return new ResultVo(Contants.FAIL_CODE,"修改失败");
        }

    }

    @Override
    public ResultVo del(Integer[] ids) {

        Integer user  = systemDao.del(ids);
        if (user > 0){
            return new ResultVo(Contants.SUCCESS_CODE,"删除成功");
        }else {
            return new ResultVo(Contants.FAIL_CODE,"删除失败");
        }
    }
}
